﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_QuestionMT : PX.MyPage
{
	private PX.Question.Component clsQuestionComp = new PX.Question.Component();

	protected void Page_Load(object sender, EventArgs e)
	{
		if (!IsPostBack)
		{
			BindGridView();
		}
	}

	protected override void OnInit(EventArgs e)
	{
		base.OnInit(e);

		clsQuestionComp.page = Page;
		Grv.RowDeleting += new GridViewDeleteEventHandler(Grv_RowDeleting);
		Grv.DataBound += new EventHandler(Grv_DataBound);
		LBtnFirst.Click += new EventHandler(LBtnFirst_Click);
		LBtnForward.Click += new EventHandler(LBtnForward_Click);
		LBtnNext.Click += new EventHandler(LBtnNext_Click);
		LBtnLast.Click += new EventHandler(LBtnLast_Click);
	}

	void Grv_DataBound(object sender, EventArgs e)
	{
		GridView grv = (GridView) sender;

		if (grv.PageIndex == 0)
		{
			LBtnForward.Enabled = false;
		}
		else
		{
			LBtnForward.Enabled = true;
		}
		if (grv.PageIndex == grv.PageCount - 1)
		{
			LBtnNext.Enabled = false;
		}
		else
		{
			LBtnNext.Enabled = true;
		}
	}

	void LBtnLast_Click(object sender, EventArgs e)
	{
		Grv.PageIndex = Grv.PageCount - 1;

		BindGridView();
	}

	void LBtnNext_Click(object sender, EventArgs e)
	{
		Grv.PageIndex = Grv.PageIndex + 1;

		BindGridView();
	}

	void LBtnForward_Click(object sender, EventArgs e)
	{
		Grv.PageIndex = Grv.PageIndex - 1;

		BindGridView();
	}

	void LBtnFirst_Click(object sender, EventArgs e)
	{
		Grv.PageIndex = 0;

		BindGridView();
	}
	void Grv_RowDeleting(object sender, GridViewDeleteEventArgs e)
	{
		GridView grv = (GridView)sender;
		int nDeleteID;
		PX.Question.Entity clsDeleteQuestion = new PX.Question.Entity();

		nDeleteID = Convert.ToInt32(grv.DataKeys[e.RowIndex].Value);
		clsDeleteQuestion = clsQuestionComp.GetOne(nDeleteID);

		if (clsQuestionComp.Delete(clsDeleteQuestion))
		{
			BindGridView();
			Common.ShowMessageAlert.ShowMessage(Page, "删除成功！");
		}
		else
		{

		}
	}

	private void BindGridView()
	{
		Grv.DataSource = clsQuestionComp.QueryAll();
		Grv.DataKeyNames = new string[] { "ID" };
		Grv.DataBind();
	}
}